package util;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.math.BigDecimal;

import org.apache.poi.ss.usermodel.Cell;

public class common {
	
	public static void copyfile(File f1, File f2) {
		try {
			InputStream in = new FileInputStream(f1);

			OutputStream out = new FileOutputStream(f2);

			byte[] buf = new byte[1024];
			int len;
			while ((len = in.read(buf)) > 0) {
				out.write(buf, 0, len);
			}
			in.close();
			out.close();
			System.out.println("File copied.");
		} catch (FileNotFoundException ex) {
			System.out.println(ex.getMessage() + " in the specified directory.");
			System.exit(0);
		} catch (IOException e) {
			System.out.println(e.getMessage());
		}
	}
	
	public static String getAsAlphaNumeric(Cell cell) {
		if (cell == null)
			return null;
		String value;

		if (cell.getCellType() == 0) {
			double cell1Number = cell.getNumericCellValue();

			value = new BigDecimal(Double.toString(cell1Number)).toPlainString();
		} else {
			value = cell.getStringCellValue().trim();
		}

		return value;
	}

}
